/* -*- Mode:C++; c-basic-offset:4; indent-tabs-mode:t; -*- */
#include "xodewin.h"

XodeWin::XodeWin()
    : wxFrame(NULL, wxID_ANY, _T("wxode for wxWidgets"))
{
    m_pManager = new wxAuiManager;
    m_pManager->SetManagedWindow(this);
    //
    InitialComponents();

    //
    m_pManager->Update();
}

XodeWin::~XodeWin()
{

}

BEGIN_EVENT_TABLE(XodeWin, wxFrame)
    EVT_MENU(wxID_CLOSE_ALL, XodeWin::OnCloseAll)
    EVT_MENU(wxID_CLOSE, XodeWin::OnCloseFile)
    EVT_MENU(wxID_OPEN, XodeWin::OnOpenFile)
    EVT_MENU(wxID_NEW, XodeWin::OnNewFile)
    EVT_MENU(wxID_ABOUT, XodeWin::OnAbout)
    EVT_MENU(wxID_EXIT, XodeWin::OnWinClose)
    EVT_CLOSE(XodeWin::OnClose)
END_EVENT_TABLE()

void XodeWin::OnClose(wxCloseEvent &event)
{
    if(m_pManager != NULL)
    {
        m_pManager->UnInit();
        delete m_pManager;
    }

    Destroy();
}

void XodeWin::InitialComponents()
{
    //Configure the global menu bar
    m_pMenuBar = new wxMenuBar;
    SetMenuBar(m_pMenuBar);
    InitialMenuBar();
    // TODO Configure the advanced toolbar

    // TODO configure the content
}

void XodeWin::InitialMenuBar()
{
    CreateMenuFile();
    CreateMenuEdit();
    CreateMenuView();
    CreateMenuTools();
    CreateMenuHelp();
}

void XodeWin::CreateMenuFile()
{
    wxMenu *menu = new wxMenu;

    menu->Append(wxID_NEW);
    menu->Append(wxID_OPEN);
    menu->Append(wxID_CLOSE);
    menu->Append(wxID_CLOSE_ALL, _T("Close All"));
    menu->AppendSeparator();

    menu->Append(wxID_SAVE);
    menu->Append(wxID_SAVEAS);
    menu->AppendSeparator();

    menu->Append(wxID_PAGE_SETUP, _T("Page Setup..."));
    menu->Append(wxID_PRINT);

    menu->AppendSeparator();
    menu->Append(wxID_EXIT);

    m_pMenuBar->Append(menu, _T("&File"));
}

void XodeWin::CreateMenuHelp()
{
    wxMenu *menu = new wxMenu;

    menu->Append(wxID_HELP_CONTENTS, _T("Help Contents"));
    menu->Append(wxID_HELP_SEARCH, _T("Help Search"));
    menu->AppendSeparator();
    menu->Append(wxID_ABOUT);

    m_pMenuBar->Append(menu, _T("&Help"));
}

void XodeWin::CreateMenuEdit()
{
    wxMenu *menu = new wxMenu;

    menu->Append(wxID_CUT);
    menu->Append(wxID_COPY);
    menu->Append(wxID_PASTE);
    menu->AppendSeparator();

    menu->Append(wxID_FIND);
    menu->Append(wxID_REPLACE);
    menu->Append(wxID_REPLACE_ALL, _T("Replace All"));
    menu->AppendSeparator();
    menu->Append(wxID_ANY, _T("Options..."));

    m_pMenuBar->Append(menu, _T("&Edit"));
}

void XodeWin::CreateMenuView()
{
    wxMenu *menu = new wxMenu;

    menu->AppendCheckItem(ID_MENU_CLASS_VIEW, _T("Class View"));
    menu->AppendCheckItem(ID_MENU_FILES_VIEW, _T("Files View"));
    menu->AppendSeparator();
    menu->Append(ID_MENU_CUSTOMIZED, _T("Customized..."));

    m_pMenuBar->Append(menu, _T("&View"));
}

void XodeWin::CreateMenuTools()
{
    wxMenu *menu = new wxMenu;

    m_pMenuBar->Append(menu, _T("&Tools"));
}

void XodeWin::OnWinClose(wxCommandEvent& event)
{
    //
    Close();
}

void XodeWin::OnAbout(wxCommandEvent& event)
{
    // TODO display about dialog
}

void XodeWin::OnOpenFile(wxCommandEvent& event)
{
    // TODO open file handler
}

void XodeWin::OnNewFile(wxCommandEvent& event)
{
    // TODO new file handler
}

void XodeWin::OnCloseFile(wxCommandEvent& event)
{
    // TODO close file handler
}

void XodeWin::OnCloseAll(wxCommandEvent& event)
{
    // TODO close all opened file handler
}

